package com.dexilaonian.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.dexilaonian.R;
import com.dexilaonian.adpter.RecoveryAdapter;
import com.dexilaonian.fragment.HouseFragment;
import com.dexilaonian.fragment.ServicePersonFragment;
import com.dexilaonian.ui.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class HouseKeepActivity extends BaseActivity implements View.OnClickListener {
    String[] titles = new String[]{"家政项目", "服务人员"};
    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.et_sou_text)
    EditText etSouText;
    @Bind(R.id.tv_search)
    TextView tvSearch;
    @Bind(R.id.house_project)
    TextView houseProject;
    @Bind(R.id.service_person)
    TextView servicePerson;
    @Bind(R.id.house_v1)
    View houseV1;
    @Bind(R.id.house_v2)
    View houseV2;
    @Bind(R.id.house_viewpager)
    ViewPager houseViewpager;
    private List<Fragment> house_list = new ArrayList<>();
    private RecoveryAdapter recoveryAdapter;
    private HouseFragment housetFragment;
    private ServicePersonFragment servicepersonFragment;

    @Override
    public int getLayoutID() {
        return R.layout.activity_house_keep;
    }

    @Override
    public void initView() {
        housetFragment = new HouseFragment();
        servicepersonFragment = new ServicePersonFragment();
        house_list.add(housetFragment);
        house_list.add(servicepersonFragment);
        recoveryAdapter = new RecoveryAdapter(HouseKeepActivity.this.getSupportFragmentManager(), house_list);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        houseProject.setOnClickListener(this);
        servicePerson.setOnClickListener(this);

        houseViewpager.setAdapter(recoveryAdapter);
        houseViewpager.setCurrentItem(0);
        houseViewpager.setOffscreenPageLimit(2);
        houseViewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                changeTextColor(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }
    private void changeTextColor(int position) {
        if (position == 0) {
            houseProject.setTextColor(Color.parseColor("#009a99"));
            servicePerson.setTextColor(Color.parseColor("#333333"));
            houseV1.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
            houseV2.setBackground(null);

        } else if (position == 1) {
            servicePerson.setTextColor(Color.parseColor("#009a99"));
            houseProject.setTextColor(Color.parseColor("#333333"));
            houseV1.setBackground(null);
            houseV2.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
        }
    }
    @OnClick({R.id.back, R.id.tv_search, R.id.house_project, R.id.service_person})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.tv_search:
                break;
            case R.id.house_project:
                houseViewpager.setCurrentItem(0);
                houseProject.setTextColor(Color.parseColor("#009a99"));
                servicePerson.setTextColor(Color.parseColor("#333333"));
                houseV1.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
                houseV2.setBackground(null);
                break;
            case R.id.service_person:
                houseViewpager.setCurrentItem(1);
                servicePerson.setTextColor(Color.parseColor("#009a99"));
                houseProject.setTextColor(Color.parseColor("#333333"));
                houseV1.setBackground(null);
                houseV2.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
                break;
        }
    }
}
